package com.caipu.controller.client;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caipu.dto.DishDetailDTO;
import com.caipu.service.UserFavoriteService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.caipu.common.Result;

@RestController
@RequestMapping("/client/favorite")
@CrossOrigin
public class ClientUserFavoriteController {
    
    @Autowired
    private UserFavoriteService userFavoriteService;
    
    /**
     * 添加收藏
     */
    @PostMapping("/add")
    public Result<?> addFavorite(@RequestParam Long userId, @RequestParam Long dishId) {
        return Result.success(userFavoriteService.addFavorite(userId, dishId));
    }
    
    /**
     * 取消收藏
     */
    @PostMapping("/remove")
    public Result<?> removeFavorite(@RequestParam Long userId, @RequestParam Long dishId) {
        return Result.success(userFavoriteService.removeFavorite(userId, dishId));
    }
    
    /**
     * 检查是否已收藏
     */
    @GetMapping("/check")
    public Result<Boolean> isFavorite(@RequestParam Long userId, @RequestParam Long dishId) {
        return Result.success(userFavoriteService.isFavorite(userId, dishId));
    }
    
    /**
     * 获取用户收藏的菜品列表
     */
    @GetMapping("/list")
    public Result<Page<DishDetailDTO>> getFavoriteDishesByUser(
            @RequestParam Long userId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return Result.success(userFavoriteService.getFavoriteDishesByUser(userId, page, size));
    }
    
    /**
     * 获取用户收藏的菜品ID列表
     */
    @GetMapping("/ids")
    public Result<List<Long>> getFavoriteDishIds(@RequestParam Long userId) {
        return Result.success(userFavoriteService.getFavoriteDishIds(userId));
    }
}